import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class LuckDrawManageService {

  serviceUrls: any = {
    queryLoveLuckDrawListUrl: '/recycleRaffleActivity/list', // 下单抽奖查询 List
    setEnableStatusUrl: '/recycleRaffleActivity/enable', // 下单抽奖 启用 | 禁用

    queryLoveLuckDrawDetailsUrl: '/recycleRaffleActivity/details', // 下单抽奖 - 详情
    addLoveLuckDrawUrl: '/recycleRaffleActivity/save', // 下单抽奖 - 新增
    updateLoveLuckDrawUrl: '/recycleRaffleActivity/update', // 下单抽奖 - 编辑

    queryLoveLuckDrawRecordUrl: '/recycleRaffleActivityUserRecord/list', // 回收下单抽奖记录 List
    exportLoveLuckDrawRecordUrl: '/recycleRaffleActivityUserRecord/getExcel' // 回收抽象记录导出
  };

  constructor(public httpClient: HttpClient) { }

  // 下单抽奖查询 List
  getLoveLuckDrawListData(params: any) {
    return this.httpClient.post(this.serviceUrls.queryLoveLuckDrawListUrl, params).toPromise();
  }
  
  // 下单抽奖 启用 | 禁用
  setEnableStatusData(params: any) {
    return this.httpClient.post(this.serviceUrls.setEnableStatusUrl, params).toPromise();
  }

  // 下单抽奖 - 详情
  getLoveLuckDrawDetailsData(params: any) {
    return this.httpClient.post(this.serviceUrls.queryLoveLuckDrawDetailsUrl, params).toPromise();
  }

  /**
   * 下单抽奖 (新增 & 编辑 id)
   * @param params 
   * @returns 
   */
  modifyLoveLuckDrawData(params: any) {
    const { activity } = params || {};
    let url = activity.id ? this.serviceUrls.updateLoveLuckDrawUrl : this.serviceUrls.addLoveLuckDrawUrl;
    return this.httpClient.post(url, params).toPromise();
  }

  // 回收下单抽奖记录 List
  getLoveLuckDrawRecordData(params: any) {
    return this.httpClient.post(this.serviceUrls.queryLoveLuckDrawRecordUrl, params).toPromise();
  }

  // 回收抽奖记录 导出
  exportLoveLuckDrawRecordData(params: any) {
    return this.httpClient.get(this.serviceUrls.exportLoveLuckDrawRecordUrl, {params: params, responseType: 'blob'}).toPromise();
  }
}



